clear all
version 11
set more off

cd ~\20_emission_county_level


****************************************************************************
* 2000 part 1
****************************************************************************
insheet using emission_county_level_2000_part1.csv, names comma clear

tab tier1_code // no tier1==13

drop if pollutant_code=="CO"
drop if pollutant_code=="PM-CON"
drop if pollutant_code=="PM10-FIL"
drop if pollutant_code=="PM10-PRI"
drop if pollutant_code=="PM25-FIL"
drop if pollutant_code=="PM-FIL"
drop if pollutant_code=="PM-PRI"

gen str3 c_fips = string(county_fips,"%03.0f")
gen str3 s_fips = string(state_fips,"%02.0f")
gen fips_string = s_fips+c_fips
destring fips_string, generate(fips)
drop *_fips fips_*

collapse (sum) annual_emission, by(fips pollutant_code)

replace pollutant_code="PM25" if pollutant_code=="PM25-PRI"
reshape wide annual_emission, i(fips) j(pollutant_code) string
ren annual_emissionNH3 nh3
ren annual_emissionNOX nox
ren annual_emissionPM25 pm25
ren annual_emissionSO2 so2
ren annual_emissionVOC voc

compress
saveold emission_county_level_2000_part1, replace


****************************************************************************
* 2000 part 2
****************************************************************************
insheet using emission_county_level_2000_part2.csv, names comma clear
tab tier1_code // no tier1==13
drop if pollutant_code=="CO"
drop if pollutant_code=="PM-CON"
drop if pollutant_code=="PM10-FIL"
drop if pollutant_code=="PM10-PRI"
drop if pollutant_code=="PM25-FIL"
drop if pollutant_code=="PM-FIL"
drop if pollutant_code=="PM-PRI"

gen str3 c_fips = string(county_fips,"%03.0f")
gen str3 s_fips = string(state_fips,"%02.0f")
gen fips_string = s_fips+c_fips
destring fips_string, generate(fips)
drop *_fips fips_*

collapse (sum) annual_emission, by(fips pollutant_code)

replace pollutant_code="PM25" if pollutant_code=="PM25-PRI"
reshape wide annual_emission, i(fips) j(pollutant_code) string
ren annual_emissionNH3 nh3
ren annual_emissionNOX nox
ren annual_emissionPM25 pm25
ren annual_emissionSO2 so2
ren annual_emissionVOC voc

compress
saveold emission_county_level_2000_part2, replace


****************************************************************************
* combine two parts
****************************************************************************
use emission_county_level_2000_part1, clear
//use emission_county_level_2000_part2, clear
append using emission_county_level_2000_part2
sort fips
codebook fips // every fips appears once

compress
saveold emission_county_level_2000, replace

